package com.song.controller;

import com.song.pojo.User;
import com.song.service.IUserService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author TonySong
 * @date 2024/5/24 0024
 * @time 17:25
 */
@RestController
@RequestMapping("/users")
@Slf4j
public class UserController {

    @Resource
    private IUserService userService;
    @GetMapping("/")
    public Map<String, User>  getUsers(){
        return this.userService.getAllUser();
    }

    @PostMapping("/")
    public boolean addUser(User user){
        try{
            this.userService.add(user);
            return true;
        }catch(Exception e){
            log.error("add user error",e);
            return  false;
        }
    }

}
